from .models import save_students, load_students, Student

class RegistryService:
    
    def __init__(self):
        self.students = load_students()
    
    def add_student(self, name, age, gender, class_name):
        """添加新学生"""
        new_student = Student(name, age, gender, class_name)
        self.students.append(new_student)
        save_students(self.students)
        return new_student
    
    def find_student(self, name):
        """按姓名查找学生"""
        for student in self.students:
            if student.name == name:
                return student
        return None